package com.ll.menu.user.food.detail;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.droid.library.app.App;
import com.droid.library.app.mvp.BaseMVPActivity;
import com.droid.library.app.mvp.IUI;
import com.droid.library.thirdplatform.imageloader.CoreImageLoader;
import com.droid.library.utils.app.DeviceUtils;
import com.droid.library.utils.app.PixelUtil;
import com.ll.menu.user.R;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 食物详情
 *
 * @author wangheng
 */

public class FoodDetailActivity extends BaseMVPActivity<FoodDetailPresenter> implements IFoodDetailUI {

    @InjectView(R.id.ivFoodDetailImage)
    ImageView mImageView;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_food_detail;
    }

    @Override
    protected void onCreateExecute(Bundle savedInstanceState) {

        int screenWidth = DeviceUtils.getScreenWidth(App.getInstance().getContext());
        if(!isPortrait(this)){
            screenWidth = DeviceUtils.getScreenHeight(App.getInstance().getContext());
        }
        int appbarHeight = App.getInstance().getResources().getDimensionPixelOffset(R.dimen.appbar_height);
        int padding = PixelUtil.dip2px(6) * 2;

        int size = screenWidth - appbarHeight - padding;

        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mImageView.getLayoutParams();
        lp.width = size;
        lp.height = size;
        mImageView.setLayoutParams(lp);

        CoreImageLoader.getInstance().display(mImageView,
                "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523022603256&di=9444988d15f64feab6dd02daf2b97ba8&imgtype=0&src=http%3A%2F%2Fpic.nipic.com%2F2008-07-11%2F200871116056997_2.jpg"
                ,R.drawable.default_image);

    }

    public boolean isPortrait(Context context) {
        return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    }

    @Override
    protected FoodDetailPresenter createPresenter() {
        return new FoodDetailPresenter();
    }

    @Override
    protected IUI getUI() {
        return FoodDetailActivity.this;
    }

    @OnClick({R.id.ivFoodDetailBack,R.id.tvFoodDetailButton})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ivFoodDetailBack:
                finishActivity();
                break;
            case R.id.tvFoodDetailButton:

                break;
            default:

                break;
        }
    }

    public static void launch(Activity activity){
        Intent intent = new Intent(activity,FoodDetailActivity.class);
        activity.startActivity(intent);
    }
}
